package com.metaera.app.controller.presenter;

import com.metaera.app.controller.core.RequestPresenter;
import com.metaera.app.controller.view.core.INetworkRequestView;
import com.metaera.app.data.DataRepository;
import com.metaera.app.data.model.BasicResponse;
import com.metaera.app.data.rx.ResponseObserver;
import com.metaera.app.data.rx.SchedulersTransformer;

import io.reactivex.Observable;

public class LikeInformationPresenter extends RequestPresenter<INetworkRequestView<Object>> {

    // 点赞
    public void like(int id, boolean status) {
        DataRepository.getInstance()
                .likeInformation(id, status ? 1 : 0, 1)
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }


    // 利空
    public void deny(int id, boolean status) {
        DataRepository.getInstance()
                .likeInformation(id, status ? 1 : 0, 2)
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }

    public void collection(int id, boolean status) {
        Observable<BasicResponse<Object>> observable;
        if (status) {
            observable = DataRepository.getInstance().collectionInformation(id);

        } else {
            observable = DataRepository.getInstance().cancelCollectionInformation(id);
        }

        observable.compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }

}
